# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libtool

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.2.418
pkgrel=1
pkgdesc="A system independent dlopen wrapper for GNU libtool (mingw-w64)"
arch=('any')
url="http://www.gnu.org/software/libtool"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
groups=("${MINGW_PACKAGE_PREFIX}")
options=('staticlibs' 'strip')
source=(#"http://ftp.gnu.org/pub/gnu/libtool/libtool-${pkgver}.tar.xz"
        ftp://alpha.gnu.org/gnu/libtool/libtool-2.4.2.418.tar.xz{,.sig}
        0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
        0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
        0004-Fix-linking-with-fstack-protector.mingw.patch
        0005-Fix-seems-to-be-moved.patch
        0006-Fix-strict-ansi-vs-posix.patch
        0007-fix-cr-for-awk-in-configure.all.patch
        0008-find-external-libraries.patch)
md5sums=('9f4aab3462f86b552f3ac74980d35308'
         'SKIP'
         '091163f2cc8c2dd8c8d5574181eb53e1'
         '8ec5b2977ce8c2188246873194100c04'
         'e34e8d23ebb7afcf3a0632373dc6f6fb'
         'bb4e559afa91865c0f9e489e19507922'
         'cfc5378b9d8ac56800489841b8b90101'
         '2200a7e2cfa8f5f3f9811f03ed41c46a'
         '952d3f9e5e06956244db7a751aa6739a')

prepare() {
  cd ${srcdir}/libtool-${pkgver}
  patch -p1 -i ${srcdir}/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
  patch -p1 -i ${srcdir}/0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
  patch -p1 -i ${srcdir}/0004-Fix-linking-with-fstack-protector.mingw.patch
  patch -p1 -i ${srcdir}/0005-Fix-seems-to-be-moved.patch
  patch -p1 -i ${srcdir}/0006-Fix-strict-ansi-vs-posix.patch
  patch -p1 -i ${srcdir}/0007-fix-cr-for-awk-in-configure.all.patch
  patch -p1 -i ${srcdir}/0008-find-external-libraries.patch
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../libtool-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="$pkgdir" install
}

